package main

import (
	"os"
	"ox-love/common"
	"ox-love/router"

	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
	"github.com/spf13/viper"
)

func main() {
	//读取配置
	InitConf()
	//连接数据库
	db := common.InitDB()
	defer db.Close()

	app := gin.Default()
	//路由
	app = router.CollectRoute(app)
	//gin.SetMode("dev")
	panic(app.Run(":" + viper.GetString("server.port")))
}

func InitConf() {
	wordDir, _ := os.Getwd()
	viper.SetConfigName("config")
	viper.SetConfigType("yml")
	viper.AddConfigPath(wordDir + "/conf")
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
}
